package member.base.action;

import m.common.action.ActionRequest;
import m.common.action.Param;
import m.common.action.RequestMethod;
import m.common.model.util.*;
import m.system.exception.MException;
import m.system.util.JSONMessage;
import member.base.model.ServeType;
import member.base.model.UserInfo;
import member.base.util.PowerUtil;

import java.sql.SQLException;

@ActionRequest(name = "action/base/serveType",description = "服务类型")
public class ServeTypeAction extends BaseAction {
    @RequestMethod(description = "全部列表")
    public JSONMessage getAll() throws Exception {
        return JSONMessage.success("查询成功")
        .push("list",
            ModelQueryList.getModelList(ServeType.class,new String[]{"*"},null,
                QueryCondition.eq("business.oid", PowerUtil.getBusiness().getOid())
            )
        );
    }
    @RequestMethod(description = "保存")
    public JSONMessage save(@Param("model") ServeType model) throws Exception {
        PowerUtil.verifyPower(UserInfo.PowerManage);
        model.setBusiness(PowerUtil.verifyBusiness(model.getBusiness()));
        ModelQueryCheck.init(model)
            .checkNotNull("color","颜色不能为空")
            .checkNotNull("name","名称不能为空")
            .doCheck(false,true);
        ModelCheckUtil.checkUniqueCombine(model,new String[]{"business.oid","name"},"名称已存在");
        ModelUpdateUtil.saveModel(model);
        return JSONMessage.success("保存成功");
    }
}
